<!--待派件-->
<template>
  <div>
    <el-form :model="checkForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="办理结果" prop="approveStatus"  :rules="[{ required: true, message: '请选择办理结果', trigger: 'change' }]" style="width: 100%;">
        <el-radio-group v-model="checkForm.approveStatus" @change="handleChange">
          <el-radio label="3" class="red">退件</el-radio>
          <el-radio label="9" class="red">分派信采</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="下户时间" prop="appointNextTime" v-if="checkForm.approveStatus === '9'">
        <el-date-picker v-model="checkForm.appointNextTime" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="派件信采" prop="checkerId" v-if="sendCheckPerson && checkForm.approveStatus == '9'" required>
        <el-select v-model="checkForm.checkerId" placeholder="请选择">
          <el-option
            v-for="item in sendCheckPersons"
            :key="item.id"
            :label="item.nameAndMobile"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      
      <el-form-item label="反馈信息" prop="opinion">
           <el-input type="textarea" :rows="7" v-model="checkForm.opinion" style="width: 300px"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm(checkForm)" v-loading="loading">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import { deliverySend, listUserByRole } from '@/api/project'
export default {
  props: {
     projectId: undefined,
     taskId: undefined,
     appointNextTime: undefined
    },
  data() {
    return {
      checkForm: {
        appointNextTime: this.appointNextTime,
        checkerId: undefined,
        projectId: undefined,
        approveStatus:undefined,
        opinion:undefined
      },
      sendCheckPerson: true,
      sendCheckPersons: [],
      value: '',
      loading: false
    };
  },
  created() {
    this.findUsers();
    this.checkForm.appointNextTime = this.appointNextTime;
  },
  methods: {
    submitForm() {
      this.checkForm.projectId = this.projectId,
      this.checkForm.taskId = this.taskId,
      this.$confirm('你确定要提交吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 开始提交信息
        this.loading = true;
        deliverySend(this.checkForm)
          .then((data) => {
            this.loading = false;
               this.$notify.success({
                title: '成功',
                message: '操作成功'
              })
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.go(-1);
          }).catch(() => {
            this.loading = false;
          })
      })
    },
    findUsers() {
      // 查询数据 构造页面
      listUserByRole('尽职调查岗')
        .then((data) => {
          this.sendCheckPersons = data.data;
          console.log('响应数据:%o', data);
        })
        .catch((error) => {
          console.error('请求用户数据发生异常:' + error);
        });
    },
    restForm() {
      this.checkForm = {
        appointNextTime: undefined,
        checkerId: undefined,
        opinion:undefined,
        approveStatus:undefined,

      };
    },
    handleChange(node) {
      this.restForm();
      this.checkForm.approveStatus = node;
      if(node == '9') {
        this.checkForm.appointNextTime = this.appointNextTime
      }
    },
  },
};
</script>
